package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.vo.TimeCountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;



@RestController
@RequestMapping("/customer/reservation")
public class CustomerReservationController extends BaseController {
    @Autowired
    private CustomerReservationService customerReservationService;

    /**
     * 查询取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> cancelQuantity(){
        Integer quantity=customerReservationService.cancelQuantity();
        return success(quantity) ;
    }

    /**
     * 查询每个时段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public ResponseResult countByTime(Long time){
        //封装一个实体类,查询出每个时段的预约次数
        List<TimeCountVo> list=customerReservationService.countByTime(time);
        return  success(list);
    }

    /**
     * 添加预约
     * @param reservationDto
     * @return
     */
    @PostMapping
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto){
        customerReservationService.addReservation(reservationDto);
        return success();
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/page")
    public ResponseResult<PageResponse> getPage(Integer pageNum, Integer pageSize, Integer status){
       PageResponse pageResponse= customerReservationService.getPage(pageNum,pageSize,status);
        return success(pageResponse);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public ResponseResult cancelReservation(@PathVariable Long id){
        customerReservationService.cancel(id);
        return success();
    }
}

